const app = getApp()
const http = (url, data = {}, method = 'get') => {
    let path = app.globalData.baseUrl + url
    let token = wx.getStorageSync('token')
    let openid= wx.getStorageSync('openid')
    return new Promise((resolve, reject) => {
        wx.request({
            url: path,
            data: method=="get" ? data : JSON.stringify(data),
            method: method,
            header: {
                "openid":openid,
                'content-type': 'application/json', // 默认值
                'Authorization':token
            },
            success(res) {
                resolve(res.data)
            },
            fail(res) {
                reject(res.data);
            }
        })
    })
}
const get = (url, data) => http(url, data, 'get')
const post = (url, data) => http(url, data, 'post')
module.exports = {
    get,
    post,
}